package servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import dao.UserDao;
import service.Service;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;
@WebServlet(name = "GetComment", value = "/getComment")
public class GetComment extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String src = req.getParameter("src");
        Service service = new Service();
        List list = service.getComment(src);
        ObjectMapper mapper = new ObjectMapper();
        resp.setContentType("application/json;charset=utf-8");
        mapper.writeValue(resp.getWriter(),list);
//        String rs=null;
//        rs = mapper.writeValueAsString(list);
//        System.out.println("1");
//        System.out.println(rs.length());
//        System.out.println("2");
//        resp.setCharacterEncoding("utf-8");
//        resp.getWriter().write(rs);
//        mapper.writeValue(resp.getOutputStream(),list);
//        resp.setContentType("application/json;charset=utf-8");
//        mapper.writeValue(resp.getWriter(),list);



    }
}
